Skip to content

fix: name the engine and the binding in execute_engine failures - #4682

Merged
apbose merged 2 commits into
pytorch:mainfrom
SrivastavaKshitij:fix/execute-engine-diagnostics
Sep 30, 2026
Merged

apbose merged 2 commits into
pytorch:mainfrom
SrivastavaKshitij:fix/execute-engine-diagnostics

Conversation

@SrivastavaKshitij

@SrivastavaKshitij SrivastavaKshitij commented Sep 4, 2026 •

Copy link
Copy Markdown

Description

Every runtime check in execute_engine says what went wrong and none says where. On a model
with 14 engines that is all the caller gets — and because a refused engine writes none of its
outputs, what usually surfaces first is an unrelated node reading one of them.

Diagnostics only, no behavior change. Each check now carries the engine name and the binding
index and name, the input-shape check reports the shape TensorRT refused next to the one the
engine declares, and both allocations are caught and re-thrown naming the engine and the size
it asked for, appending to the allocator's message rather than replacing it. TORCHTRT_CHECK
only evaluates its message on failure, so the success path is unchanged.

Before:

Expected input tensors to have device cuda, found device cpu
Expected input tensors to have type Float, found type int
Error while setting the input shape
Error while setting the tensor address for shape inputs
Failed to bind tensor address for x
Error while setting the output tensor address
The shapes of the inputs: [x] cannot be inferred. This could happen if ...
<the allocator's own error, uncaught, for the output tensors>
<the allocator's own error, uncaught, for the activation workspace>

After:

Input 0 ("x") of engine _run_on_acc_0_engine must be on a CUDA device, found device cpu
Input 0 ("x") of engine _run_on_acc_0_engine expects type Float, found type int
Error while setting the input shape for input 0 ("x") of engine _run_on_acc_0_engine. TensorRT refused shape [8, 17], the engine declares [8, 16]
Error while setting the tensor address for shape input 0 ("x") of engine _run_on_acc_0_engine
Failed to bind the tensor address for input 0 ("x") of engine _run_on_acc_0_engine
Error while setting the tensor address for output "output0" of engine _run_on_acc_0_engine
The shapes of the inputs: [x] of engine _run_on_acc_0_engine cannot be inferred. This could happen if ...
Failed to allocate output "output0" of engine _run_on_acc_0_engine with shape [8, 16] and dtype Float.
Failed to allocate the 134217728-byte activation workspace of engine _run_on_acc_0_engine.

torch.ops.tensorrt.set_logging_level(4) does not help, because the LOG_DEBUG that names the
binding runs after the check that throws. TensorRT does report the shapes on the
setInputShape path, but only to its own logger, never into the exception.

Issues

Closes #4678

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • adds a new unit test tests/py/dynamo/runtime/test_engine_failure_diagnostics.py
  • existing unit tests pass

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@SrivastavaKshitij

Copy link
Copy Markdown
Author

@apbose : looks like CI is failing on unrelated issue

@apbose
apbose force-pushed the fix/execute-engine-diagnostics branch from a009960 to 2b8cb7a Compare September 23, 2026 05:29
@apbose

apbose commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

approved. waiting on CI run after rebase for merging

@lanluo-nvidia

Copy link
Copy Markdown
Collaborator

Hi @SrivastavaKshitij,
Could you please rebase and resolve the conflict as soon as possible, we are cutting the v2.15.0 branch next week, try to get everything in to the main before branch cut.

SrivastavaKshitij and others added 2 commits September 29, 2026 23:28
Every runtime check in `execute_engine` reported what went wrong and none
reported where. On a model with 14 engines the caller sees only:

    Expected input tensors to have type Int, found type long int
    Error while setting the input shape
    CUDA out of memory. Tried to allocate 15.62 GiB.

`torch.ops.tensorrt.set_logging_level(4)` does not help, because the `LOG_DEBUG`
that names the binding runs after the check that throws.

Each check in `setup_input_tensors`, `create_output_tensors`, and the output
binding loop now carries the engine name and the binding index and name. The
input-shape check also reports the shape TensorRT refused alongside the one the
engine declares, which TensorRT writes only to its own logger. Both allocations
are caught and re-thrown with the engine that asked and the size it asked for,
keeping the original allocator message.

The messages the new code composes take these forms:

    Input <i> ("<binding>") of engine <engine> expects type <t>, found type <t>
    Error while setting the input shape for input <i> ("<binding>") of engine
      <engine>. TensorRT refused shape <dims>, the engine declares <dims>
    Failed to allocate the <n>-byte activation workspace of engine <engine>.
      <original allocator message>

`tests/py/dynamo/runtime/test_engine_failure_diagnostics.py` asserts the engine
name, the binding name, and both shapes are present. Both tests fail against the
current runtime.

Fixes pytorch#4678
@SrivastavaKshitij
SrivastavaKshitij force-pushed the fix/execute-engine-diagnostics branch from 2b8cb7a to 53539f8 Compare September 29, 2026 23:34
@SrivastavaKshitij

Copy link
Copy Markdown
Author

Hi @SrivastavaKshitij, Could you please rebase and resolve the conflict as soon as possible, we are cutting the v2.15.0 branch next week, try to get everything in to the main before branch cut.

Done!

@apbose
apbose merged commit 185bfdc into pytorch:main Sep 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] execute_engine input checks name neither the engine nor the binding that failed

3 participants